//
//  SecurityTaskProcessCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/5/19.
//

import Foundation
import UIKit

class SecurityTaskProcessCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        if highlighted {
            self.backgroundColor = .hex("#ECECEC")
        } else {
            self.backgroundColor = .white
        }
    }
    
    func buildData(data: BaglRwwcjdLzrModel) {
        titleLabel.text = data.lzrmc
        stateTextLabel.text = data.wcFlag == true ? "已完成" : "未完成"
        stateTextLabel.textColor = data.wcFlag == true ? .hex("#BFBFBF") : .hex("#FF0000")
    }

    func setupUI() {
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalTo(self)
        }

        addSubview(arrowIV)
        arrowIV.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
            make.width.equalTo(10)
        }
        
        addSubview(stateTextLabel)
        stateTextLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(arrowIV.snp.left).offset(-10)
            make.height.equalTo(14)
        }

        addSubview(line)
        line.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(0.5)
            make.bottom.equalToSuperview()
        }
    }
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.hex("#333333")
        label.font = UIFont.systemFont(ofSize: 17)
        return label
    }()

    lazy var stateTextLabel: UILabel = {
        let label = UILabel()
        label.textColor = .hex("#B6B6B6")
        label.font = .systemFont(ofSize: 15)
        label.textAlignment = .right
        return label
    }()

    lazy var arrowIV: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(systemName: "chevron.right")
        imageView.tintColor = UIColor.hex("#A5A5A5")
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    lazy var line: UIView = {
        let view = UIView.createLine()
        return view
    }()
}
